#include "string.h"
#include "uart_send.h"
#include "uart_decode.h"
#include "uart_process.h"
#include "user_cfg.h"


uart_tx_t tx_buf[2];
unsigned char tx_flag[2];

void Uart_Send_Init(uart_dev_t dev, uart_cfg_t *cfg)
{
    tx_buf[dev].buf = cfg->buf;
    tx_buf[dev].buf_size = cfg->len;
    tx_buf[dev].len = 0;
    tx_buf[dev].send_cnt = 0;
    tx_flag[dev] = 0;
}


void Uart_Send(uart_dev_t dev, unsigned char *buf, unsigned char len)
{
    memcpy(&tx_buf[dev].buf[0], buf, len);
	tx_buf[dev].len = len;
    tx_buf[dev].send_cnt = 0;
    while(tx_buf[dev].send_cnt != tx_buf[dev].len) {
        tx_flag[dev] = FALSE;
        if (UARTY == dev) {
            USART_SendData(USARTy, tx_buf[dev].buf[tx_buf[dev].send_cnt++]);
			USART_ConfigInt(USARTy, USART_INT_TXDE, ENABLE);
        } else if (UARTZ == dev) {
            // USART_SendData(USART2, tx_buf[dev].buf[tx_buf[dev].send_cnt++]);
			// UART_Interrput_Enable(UARTz, UART_INT_TXDE);
        }
        while(!tx_flag[dev]);//等待一次发送完成   //出不来；
    }
}

void Uart_Send_Irq(uart_dev_t dev)
{
    tx_flag[dev] = TRUE;
}
